Skip to content

Additional Sample Format for USB Audio Streaming in usb_device_uac (AEGHB-1139) #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Schuwi
Copy link

@Schuwi Schuwi commented Jul 12, 2025

Description

This PR addresses several issues and improvements in the usb_host_uac library:

  1. Fix build failure when no microphone/speaker channel is configured:

    • Resolved compilation errors that occurred when UAC_MIC_CHANNEL_NUM or UAC_SPK_CHANNEL_NUM were set to 0.
  2. Add configurable sample format:

    • Introduced support for floating-point precision in audio streaming, enabling higher data precision beyond 16-bit PCM.
    • The library now supports two sample formats: 16-bit PCM and floating-point precision. Supporting arbitrary data sizes would require more extensive API changes.
  3. Fix mixup of TX/RX, IN/OUT:

    • Corrected inconsistencies in naming and functionality for TX/RX and IN/OUT, reducing confusion and improving reliability during development/debugging.

These changes make it easier to stream microphone data over USB with enhanced precision and fix critical issues in the library.

Related

  • No specific issue linked.
  • This PR is related to debugging and development improvements for USB audio streaming.

Testing

  • Tested the changes in my application with a microphone-only setup (no speaker).
  • Verified that audio streaming worked correctly with the new floating-point sample format and fixed TX/RX and IN/OUT mixups.
  • Confirmed that the library builds successfully and streams audio data as expected.

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes. (I don't think so, the Kconfig changes are backward-compatible)
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed. (Unclear)
  • Tests are updated or added as necessary. (I didn't find any related tests)
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@CLAassistant
Copy link

CLAassistant commented Jul 12, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

github-actions bot commented Jul 12, 2025

Fails
🚫

node failed.

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "fix(usb_host_uac): mixup of mic/spk":
    • summary looks too short

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

Messages
📖 You might consider squashing your 4 commits (simplifying branch history).

Log

┌─────────┬─────────────────────────────────────┬───────────────────────────────────────────────────────┬────────────────┐
│ (index) │             CiVariable              │                         Value                         │ CustomSettings │
├─────────┼─────────────────────────────────────┼───────────────────────────────────────────────────────┼────────────────┤
│    0    │  'ENABLE_RULE_PR_COMMIT_MESSAGES'   │                         true                          │   'default'    │
│    1    │    'ENABLE_RULE_PR_DESCRIPTION'     │                         true                          │   'default'    │
│    2    │     'ENABLE_RULE_PR_SIZE_LINES'     │                         true                          │   'default'    │
│    3    │ 'ENABLE_RULE_PR_SOURCE_BRANCH_NAME' │                         true                          │   'default'    │
│    4    │   'ENABLE_RULE_PR_TARGET_BRANCH'    │                         true                          │   'default'    │
│    5    │  'ENABLE_RULE_PR_TOO_MANY_COMMITS'  │                         true                          │   'default'    │
│    6    │    'ENABLE_OUTPUT_INSTRUCTIONS'     │                         true                          │   'default'    │
│    7    │             'CLA_LINK'              │                          ''                           │   'default'    │
│    8    │   'COMMIT_MESSAGE_ALLOWED_TYPES'    │ 'change,ci,docs,feat,fix,refactor,remove,revert,test' │   'default'    │
│    9    │      'CONTRIBUTING_GUIDE_FILE'      │                          ''                           │   'default'    │
│   10    │   'IGNORED_SECTIONS_DESCRIPTION'    │              'related,release,breaking'               │   'default'    │
│   11    │         'IS_GITLAB_MIRROR'          │                         false                         │   'default'    │
│   12    │   'MAX_COMMIT_MESSAGE_BODY_LINE'    │                          100                          │   'default'    │
│   13    │    'MAX_COMMIT_MESSAGE_SUMMARY'     │                          72                           │   'default'    │
│   14    │         'MAX_COMMITS_WARN'          │                           5                           │   'default'    │
│   15    │            'MAX_COMMITS'            │                           2                           │   'default'    │
│   16    │           'MAX_PR_LINES'            │                         1000                          │   'default'    │
│   17    │    'MIN_COMMIT_MESSAGE_SUMMARY'     │                          20                           │   'default'    │
│   18    │     'MIN_PR_DESCRIPTION_LENGTH'     │                          50                           │   'default'    │
└─────────┴─────────────────────────────────────┴───────────────────────────────────────────────────────┴────────────────┘
Error:  RequestError [HttpError]: API rate limit exceeded for 172.184.210.163. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
    at /node_modules/@octokit/request/dist-node/index.js:86:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 403,
  response: {
    url: 'https://api.github.com/repos/espressif/esp-iot-solution',
    status: 403,
    headers: {
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-RateLimit-Used, X-RateLimit-Resource, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
      connection: 'close',
      'content-length': '281',
      'content-security-policy': "default-src 'none'; style-src 'unsafe-inline'",
      'content-type': 'application/json; charset=utf-8',
      date: 'Thu, 24 Jul 2025 06:53:25 GMT',
      'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
      server: 'Varnish',
      'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'deny',
      'x-github-media-type': 'github.v3; format=json',
      'x-github-request-id': '981D:358A6:1B9BAD7:1C89DAD:6881D865',
      'x-ratelimit-limit': '60',
      'x-ratelimit-remaining': '0',
      'x-ratelimit-reset': '1753342647',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '60',
      'x-xss-protection': '1; mode=block'
    },
    data: {
      message: "API rate limit exceeded for 172.184.210.163. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
      documentation_url: 'https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting'
    }
  },
  request: {
    method: 'GET',
    url: 'https://api.github.com/repos/espressif/esp-iot-solution',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-rest.js/18.12.0 octokit-core.js/3.6.0 Node.js/18.15.0 (linux; x64)'
    },
    request: { hook: [Function: bound bound register] }
  }
}
danger-results://tmp/danger-results-b19a25be.json

Generated by 🚫 dangerJS against 8afba53

@github-actions github-actions bot changed the title Additional Sample Format for USB Audio Streaming in usb_host_uac Additional Sample Format for USB Audio Streaming in usb_host_uac (AEGHB-1139) Jul 12, 2025
@leeebo leeebo changed the title Additional Sample Format for USB Audio Streaming in usb_host_uac (AEGHB-1139) Additional Sample Format for USB Audio Streaming in usb_device_uac (AEGHB-1139) Jul 24, 2025
@leeebo leeebo requested a review from Copilot July 24, 2025 06:54
@leeebo leeebo self-assigned this Jul 24, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the USB Device UAC (USB Audio Class) library with configurable sample formats and fixes critical TX/RX and IN/OUT terminology mixups. The changes enable floating-point audio precision beyond 16-bit PCM and resolve build failures when microphone or speaker channels are disabled.

  • Corrected TX/RX and IN/OUT naming confusion throughout the codebase to align with USB perspective conventions
  • Added configurable sample format support for both PCM (16-bit) and IEEE floating-point (32-bit) formats
  • Fixed conditional compilation guards to prevent build failures when channels are set to 0

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
usb_device_uac.c Fixed TX/RX macro confusion and added conditional guards for channel configuration
uac_descriptors.h Added sample format macros and updated descriptor definitions to use configurable formats
uac_config.h Added sample format configuration macros based on Kconfig settings
tusb_config_uac.h Corrected TX/RX channel assignments, added format-specific configurations, and improved documentation
Kconfig.uac Added new configuration choices for SPK and MIC sample formats

@@ -56,6 +56,18 @@ enum {
#define UAC2_ENTITY_MIC_FEATURE_TERMINAL 0x12
#define UAC2_ENTITY_MIC_OUTPUT_TERMINAL 0x13

#if SPK_FORMAT_PCM
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro SPK_FORMAT_PCM may be undefined when neither PCM nor FLOAT is selected, leading to undefined behavior. Consider adding an #else clause with a default format or an #error directive to catch invalid configurations.

Copilot uses AI. Check for mistakes.

#define SPK_SAMPLE_FORMAT AUDIO_DATA_FORMAT_TYPE_I_IEEE_FLOAT
#endif

#if MIC_FORMAT_PCM
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro MIC_FORMAT_PCM may be undefined when neither PCM nor FLOAT is selected, leading to undefined behavior. Consider adding an #else clause with a default format or an #error directive to catch invalid configurations.

Copilot uses AI. Check for mistakes.


// Sample type
#if SPK_FORMAT_PCM
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing #else clause for SPK format configuration. If neither SPK_FORMAT_PCM nor SPK_FORMAT_FLOAT is defined, the RX sample configuration will be undefined, leading to compilation errors.

Copilot uses AI. Check for mistakes.

#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX 32
#endif

#if MIC_FORMAT_PCM
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing #else clause for MIC format configuration. If neither MIC_FORMAT_PCM nor MIC_FORMAT_FLOAT is defined, the TX sample configuration will be undefined, leading to compilation errors.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants